<?php
/**
 * Created by PhpStorm.
 * User: tangping
 * Date: 16/4/24
 * Time: 下午10:45
 */

namespace Events;
use Library\Common;
use Models\Tlog;


class user extends  Base
{

    public static  function afterUpdate($data=[]){
       $b= parent::afterUpdate($data);
        if($b === -11){
            return -11;
        }
        $tlog=new Tlog();
        $key=$data['model'].'_'.$b->id;
        $before=self::getBefore($key);
        if($before && $b->loginnum > $before['loginnum']){
            $bstop=$tlog->save([
                'uid'=>$b->id,
                'action'=>$data['action'],
                'description'=>'用户ID为:'.$b->id.'的用户于'.date('Y-m-d H:i:s').' 登录了系统'
            ]);
        }else{
            $bstop=$tlog->save([
                'uid'=>$b->id,
                'action'=>$data['action'],
                'description'=>'用户ID为:'.$b->id.'的用户于'.date('Y-m-d H:i:s').' 更新了资料'
            ]);
        }
        return true;
    }
}